package org.hbgl.geoentity.db.util;

import org.apache.commons.lang3.ObjectUtils;

public enum CompareValueEnum {

    Long(){
        @Override
        public Boolean compareValue( Object var1, Object var2) {
            Long v1 = (Long) var1;
            Long v2 = (Long) var2;
            if(ObjectUtils.equals(v1,v2)){
                return true;
            }
            return false;
        }
    },
    Boolean(){
        @Override
        public Boolean compareValue( Object var1, Object var2) {
            Boolean v1 = (Boolean) var1;
            Boolean v2 = (Boolean) var2;
            if(ObjectUtils.equals(v1,v2)){
                return true;
            }
            return false;
        }
    },
    Integer(){
        @Override
        public Boolean compareValue(Object var1, Object var2) {
            Integer v1 = (Integer) var1;
            Integer v2 = (Integer) var2;
            if(ObjectUtils.equals(v1,v2)){
                return true;
            }
            return false;
        }
    },
    String(){
        @Override
        public Boolean compareValue(Object var1, Object var2) {
            String v1 = (String) var1;
            String v2 = (String) var2;
            if(ObjectUtils.equals(v1,v2)){
                return true;
            }
            return false;
        }
    };

    public abstract Boolean compareValue(Object var1, Object var2);

    /**
     * 对比属性值是否相同
     * @param var1 属性值1
     * @param var2 属性值2
     * @return Boolean 相同：true 不同：false
     */
    public static Boolean FiledType(Object var1, Object var2){
        //获取字段类型
        String type = var1.getClass().getSimpleName();
        for (CompareValueEnum code : CompareValueEnum.values()){
            if (type.equalsIgnoreCase(code.name())){
                if(!code.compareValue(var1,var2)){
                    return false;
                }
                break;
            }
        }
        return null;
    }

}
